﻿using FM_Mono;
﻿using FibMatrix.Utils;
using UnityEngine;
using FibMatrix.Utils;

[IgnoreGen]
public class ParticleFadeInOutState :StateMachineBehaviour
{
	public string fromState;

	public string toState;

	public string particleName;

	//	  OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
	public override void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
	{
		ParticleSystem particle = CommonUtil.GetChildByName(animator.gameObject, particleName, true).GetComponent<ParticleSystem>();
		if (stateInfo.IsName(fromState))
		{
			particle.gameObject.SetActive(true);
			ParticleSystem.MainModule main = particle.main;
			main.loop = true;
		}
		else if (stateInfo.IsName(toState))
		{
			ParticleSystem.MainModule main = particle.main;
			main.loop = false;
		}
	}

	// OnStateExit is called when a transition ends and the state machine finishes evaluating this state
	public override void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
	{
		ParticleSystem particle = CommonUtil.GetChildByName(animator.gameObject, particleName, true).GetComponent<ParticleSystem>();
		if (stateInfo.IsName(fromState))
		{
			particle.gameObject.SetActive(false);
		}
	}
}
